package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/geofence")
public class GeofenceController {
    @Autowired
    GeofenceService geofenceService;

    @GetMapping("select")
    public JsonResult loadGeofence(GeofenceQuery geofenceQuery){
        log.debug("加载围栏，参数={}",geofenceQuery);
        List<GeofenceVO> list= geofenceService.loadGeofence(geofenceQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveGeofence(GeofenceSaveParam geofenceSaveParam){
        log.debug("保存围栏信息，参数:{}",geofenceSaveParam);
        geofenceService.saveGeofence(geofenceSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{geofenceId}")
    public JsonResult deleteGeofence(@PathVariable Long geofenceId){
        log.debug("删除围栏，参数={}",geofenceId);
        geofenceService.deleteGeofence(geofenceId);
        return JsonResult.ok();
    }
}
